import axios from 'axios';

export function getConfigFromGithub(gistId: string, ghToken?: string) {
  return axios
    .get(`https://api.github.com/gists/${gistId}`, {
      headers: {
        Authorization: `token ${ghToken}`,
      },
    })
    .then((res) => {
      if (res.status === 200 && res.data) {
        return res.data;
      } else {
        return null;
      }
    });
}

export function getConfigFromGitlab(gistId: string, token?: string) {
  return axios
    .get(`https://gitlab.com/api/v4/snippets/${gistId}/raw`, {
      headers: {
        'PRIVATE-TOKEN': `${token}`,
      },
    })
    .then((res) => {
      if (res.status === 200 && res.data) {
        return res.data;
      } else {
        return null;
      }
    });
}
